remove dependency on glob. (#367)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Sun, 9 Jun 2019 23:14:36 +0000 (17:14 -0600)
committerGitHub <noreply@github.com>
Sun, 9 Jun 2019 23:14:36 +0000 (17:14 -0600)
* remove dependency on glob.

and have magproto invoke the rd_deinit function when it uses the
gpx reader (uggh).

* regenerate configure on linux.

CMakeLists.txt
GPSBabel.pro
config.h.in
configure
configure.ac
magproto.cc

index 0a2f1bdadc866a59f234c48d118354c66ce9420f..0ba561b14e7e96e7378df18b24ef42b49fabc36f 100644 (file)
@@ -188,7 +188,7 @@ if(UNIX)
   if(${HAVE_STDARG_H})
     add_definitions(-DHAVE_STDARG_H)
   endif()
-  add_definitions(-DHAVE_LIBUSB -DHAVE_GLOB)
+  add_definitions(-DHAVE_LIBUSB)
   set(SOURCES ${SOURCES} gbser_posix.cc)
   set(HEADERS ${HEADERS} gbser_posix.h)
   set(JEEPS ${JEEPS} jeeps/gpslibusb.cc)
index 87c63c32c345ce866749d998cbe5e6083eaa0f09..0749981fcab338405b4590ec8a44efdd18d5a616 100644 (file)
@@ -175,7 +175,7 @@ macx|linux {
     # this is used by zlib
     DEFINES += HAVE_STDARG_H
   }
-  DEFINES += HAVE_LIBUSB HAVE_GLOB
+  DEFINES += HAVE_LIBUSB
   SOURCES += gbser_posix.cc
   HEADERS += gbser_posix.h
   JEEPS += jeeps/gpslibusb.cc
index 70f190cccdd7f5b2068db9a40ad881b00bb65507..4a39b83a401d36b2257a2b5f14ab1b019696a47e 100644 (file)
@@ -12,9 +12,6 @@
 /* define if the compiler supports basic C++14 syntax */
 #undef HAVE_CXX14
 
-/* Define to 1 if you have the `glob' function. */
-#undef HAVE_GLOB
-
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
index b0934ae456d3d6c2b22557a6496c665a4559f208..2181cae1d236bf6e7cea800e6328071c7b14fd49 100755 (executable)
--- a/configure
+++ b/configure
@@ -6673,13 +6673,12 @@ done
 # AC_FUNC_STRTOD
 # AC_FUNC_VPRINTF
 # AC_CHECK_FUNCS([atexit floor localtime_r memmove memset pow select sqrt strchr strcspn strdup strerror strncasecmp strrchr strspn strstr strtol strtoul])
-for ac_func in uname glob
+for ac_func in uname
 do :
-  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
-ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var"
-if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
+  ac_fn_cxx_check_func "$LINENO" "uname" "ac_cv_func_uname"
+if test "x$ac_cv_func_uname" = xyes; then :
   cat >>confdefs.h <<_ACEOF
-#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
+#define HAVE_UNAME 1
 _ACEOF
 
 fi
index ceaefd37859521df728955ec565c3850dd5e14e6..9cd94327bd5cd1152db73cd88f1793de77d437bd 100644 (file)
@@ -410,7 +410,7 @@ AC_CHECK_HEADERS([unistd.h stdarg.h])
 # AC_FUNC_STRTOD
 # AC_FUNC_VPRINTF
 # AC_CHECK_FUNCS([atexit floor localtime_r memmove memset pow select sqrt strchr strcspn strdup strerror strncasecmp strrchr strspn strstr strtol strtoul])
-AC_CHECK_FUNCS([uname glob])
+AC_CHECK_FUNCS([uname])
 
 #
 # There's probably some more "autoconfish" way to do this.
index 0b9da8b0027972c97e7c6acff44a9a734e06b91c..ab3ed6e91562b1d7827d4ee90f4db04e861192c7 100644 (file)
@@ -20,8 +20,6 @@
 
  */
 
-#include "defs.h"                  // might include config.h, which might define HAVE_GLOB.
-
 #include <cctype>                  // for isprint, toupper
 #include <cmath>                   // for fabs, lround
 #include <cstdio>                  // for sprintf, sscanf, snprintf, size_t
 #include <cstring>                 // for strchr, strncmp, strlen, memmove, strrchr, memset
 #include <ctime>                   // for gmtime
 
-#if HAVE_GLOB
-#include <glob.h>
-#endif
-
 #include <QtCore/QByteArray>       // for QByteArray
 #include <QtCore/QCharRef>         // for QCharRef
+#include <QtCore/QDir>             // for QDir, operator|, QDir::Files, QDir::Name, QDir::Readable
 #include <QtCore/QFileInfo>        // for QFileInfo
+#include <QtCore/QFileInfoList>    // for QFileInfoList
 #include <QtCore/QLatin1String>    // for QLatin1String
 #include <QtCore/QList>            // for QList
 #include <QtCore/QString>          // for QString, operator==
+#include <QtCore/QStringList>      // for QStringList
 #include <QtCore/QTime>            // for QTime
 #include <QtCore/Qt>               // for CaseInsensitive
 #include <QtCore/QtGlobal>         // for qPrintable, foreach
 
+#include "defs.h"
 #include "explorist_ini.h"         // for explorist_ini_done, explorist_ini_get, mag_info
 #include "gbfile.h"                // for gbfclose, gbfeof, gbfgets, gbfopen, gbfwrite, gbfile
 #include "gbser.h"                 // for gbser_deinit, gbser_init, gbser_is_serial, gbser_read_line, gbser_set_port, gbser_write, gbser_OK
@@ -80,7 +78,7 @@ static int extension_hint;
 // (This has nothing to do with the Explorist 100...600 products.)
 static ff_vecs_t* gpx_vec;
 static mag_info* explorist_info;
-static char** os_gpx_files(const char* dirname);
+static QStringList os_gpx_files(const char* dirname);
 
 /*
  * Magellan's firmware is *horribly* slow to send the next packet after
@@ -268,7 +266,7 @@ m330_cleanse(const char* istring)
                                    "abcdefghijklmnopqrstuvwxyz"
                                    "0123456789+-.'/!@#<%^&>()=:\\";
   char* rstring = (char*) xmalloc(strlen(istring)+1);
-  char* o; 
+  char* o;
   const char* i;
 
   for (o=rstring,i=istring; *i; i++) {
@@ -540,7 +538,7 @@ retry:
       if (idx > 0) {
         s.truncate(idx);
       }
-        
+
       trk_head->rte_name = s;
       track_add_head(trk_head);
     }
@@ -1249,25 +1247,25 @@ static void
 mag_read()
 {
   if (gpx_vec) {
-    char** f = os_gpx_files(explorist_info->track_path);
-    while (f && *f) {
-      gpx_vec->rd_init(*f);
+    QStringList f = os_gpx_files(explorist_info->track_path);
+    for (const auto& file : qAsConst(f)) {
+      gpx_vec->rd_init(file);
       gpx_vec->read();
-      f++;
+      gpx_vec->rd_deinit();
     }
 
     f = os_gpx_files(explorist_info->waypoint_path);
-    while (f && *f) {
-      gpx_vec->rd_init(*f);
+    for (const auto& file : qAsConst(f)) {
+      gpx_vec->rd_init(file);
       gpx_vec->read();
-      f++;
+      gpx_vec->rd_deinit();
     }
 #if 0
     f = os_gpx_files(explorist_info->geo_path);
-    while (f && *f) {
-      gpx_vec->rd_init(*f);
+    for (const auto& file : qAsConst(f)) {
+      gpx_vec->rd_init(file);
       gpx_vec->read();
-      f++;
+      gpx_vec->rd_deinit();
     }
 #endif
     return;
@@ -1582,27 +1580,18 @@ const char** os_get_magellan_mountpoints()
 #endif
 }
 
-// My kingdom for container classes and portable tree-walking...
-// Returns a pointer to a static vector that's valid until the next call.
-#if HAVE_GLOB
-static char**
+static QStringList
 os_gpx_files(const char* dirname)
 {
-  static glob_t g;
-  char* path;
-  xasprintf(&path, "%s/*.gpx", dirname);
-  glob(path, 0, nullptr, &g);
-  xfree(path);
-  return g.gl_pathv;
-}
-#else
-static char**
-os_gpx_files(const char* /* dirname */)
-{
-  fatal("Not implemented");
-  return NULL;
+  QDir dir(dirname);
+
+  const QFileInfoList filist = dir.entryInfoList(QStringList("*.gpx"), QDir::Files | QDir::Readable, QDir::Name);
+  QStringList rv;
+  for (const auto& fi : filist) {
+    rv.append(fi.absoluteFilePath());
+  }
+  return rv;
 }
-#endif
 
 /*
  *  This is repeated just so it shows up as separate menu options